<%@ page import="service.BatteryService" %>
<%@ page import="service.impl.BatteryServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Battery" %><%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-09
  Time: 14:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <style>
        table tr td {
            border: 1px solid #ccc;
        }
    </style>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>

</head>
<body>
<table>
    <tr>
        <td>信息编号</td>
        <td>车辆类型</td>
        <td>所属城市</td>
        <td>使用单位</td>
        <td>压差报警值</td>
        <td>报警时间</td>
        <td>操作</td>
    </tr>
    <%
        request.setCharacterEncoding("utf-8");
        BatteryService batteryService = new BatteryServiceImpl();
        List<Battery> list = batteryService.info();
        request.setAttribute("list",list);
    %>
    <c:forEach items="${list}" var="battery">
        <tr>
            <td><a href="<%=request.getContextPath()%>/BatterySeleteServlet?id=${battery.id}">${battery.id}</a></td>
            <td>${battery.carName}</td>
            <td>${battery.cityName}</td>
            <td>${battery.userName}</td>
            <td>${battery.pressureValue}</td>
            <td>${battery.time}</td>
            <td><a href="#" onclick="Delete(${battery.id})">删除</a></td>
        </tr>
    </c:forEach>
</table>
<script>
    function Delete(id) {
        var sf =confirm("确定要删除吗？")
        if (sf == true){
        $.get("<%=request.getContextPath()%>/BatteryDeleteServlet","id="+id,function (data){
            if (data >0){
            alert("删除成功!")
                location.href="./powerbattery_All.jsp";
            }else {
                alert("删除失败!")
            }
        })
        }
    }
</script>
</body>
</html>
